package com.wx.cloud.user.service.impl;

import com.wx.cloud.user.mapper.LoginInfoMapper;
import com.wx.cloud.user.model.LoginInfo;
import com.wx.cloud.user.repository.LoginInfoRepository;
import com.wx.cloud.user.service.LoginInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("loginInfoService")
public class LoginInfoServiceImpl implements LoginInfoService {

    @Autowired
    private LoginInfoMapper loginInfoMapper;

    @Autowired
    private LoginInfoRepository loginInfoRepository;

    @Override
    public List<LoginInfo> getSelectList(Map<String, Object> data) {
        int page = Integer.parseInt((String) data.get("pageNum"));
        int size = Integer.parseInt((String)data.get("pageSize"));
        data.put("pageNum",(page-1)*size);
        data.put("pageSize",size);
        return loginInfoMapper.getSelectList(data);
    }

    @Override
    public int getSelectCount(Map<String, Object> data) {
        return loginInfoMapper.getSelectCount(data);
    }

    @Override
    public LoginInfo getLoginInfoById(Integer id) {
        return loginInfoMapper.getLoginInfoById(id);
    }

    @Override
    public int delLoginInfo(LoginInfo loginInfo) {
        return loginInfoMapper.delLoginInfo(loginInfo);
    }

    @Override
    public String batchDeletion(List<Integer> ids) {
        Map params = new HashMap();
        params.put("ids",ids);
        int result = loginInfoMapper.batchDeletion(params);
        if (result>0){
            return "success";
        }else {
            return "false";
        }
    }

    @Override
    public int saveLoginInfo(LoginInfo loginInfo) {
        try {
            loginInfoMapper.saveLoginInfo(loginInfo);
            loginInfoRepository.save(loginInfo);
        } catch (Exception e){
            System.out.println("elasticsearch未开启");
        }
        return loginInfo.getId();
    }
}
